#pragma once

#include "Common.h"

//单例模式
class CentralCache
{
public:
    //懒汉模式
    static CentralCache* GetInStance()
    {
        return &_sInst;
    }

    //获取一个非空的span
    Span* GetOneSpan(SpanList& list, size_t byte_size);

    //从中心缓存获取一定数量的对象给thread cache
    size_t FetchRangeObj(void*& start, void*& end, size_t batchNum, size_t size);

    //将一定数量的对象释放到span跨度
    void ReleaseListToSpans(void* start, void* end, size_t byte_size);

private:
    SpanList _spanLists[NFREELIST]; //Centralcache的哈希桶个数与threadcache的桶个数相同

private:
    static CentralCache _sInst;

private:
    CentralCache()
    {}

    CentralCache(const CentralCache&) = delete;
};